%%%%% --------------------------------------------------------------------------------
%%
%%%%***************************** Version Information ********************************
%%
%% this is the "commons.sty" package used for configure document styles
%% Copyright (C) Hanlin Tan <hanlin_tan@nudt.edu.cn> 
%% This is free software: you can redistribute it and/or modify it
%% under the terms of the GNU General Public License as published by
%% the Free Software Foundation, either version 3 of the License, or
%% (at your option) any later version.
%%
\NeedsTeXFormat{LaTeX2e}[1995/12/01]
\ProvidesPackage{commons}
[2014/10/01 v0.1 commons 
macros package]
%%%%% --------------------------------------------------------------------------------
%%
%%%%******************************* Declare Options **********************************
%%
\newif\ifCOMMONS@myhdr \COMMONS@myhdrfalse
\DeclareOption{myhdr}{% user defined header and footer style
    \COMMONS@myhdrtrue%
}
\newif\ifCOMMONS@lscape \COMMONS@lscapefalse
\DeclareOption{lscape}{% landscape layout
    \COMMONS@lscapetrue%
}
\newif\ifCOMMONS@geometry \COMMONS@geometryfalse
\DeclareOption{geometry}{% enable geometry for redefining page layout
    \COMMONS@geometrytrue%
}
\newif\ifCOMMONS@numbered \COMMONS@numberedtrue
\newif\ifCOMMONS@authoryear \COMMONS@authoryearfalse
\newif\ifCOMMONS@alpha \COMMONS@alphafalse
\DeclareOption{numbered}{% enable numbered citation style
    \COMMONS@numberedtrue%
    \COMMONS@authoryearfalse
    \COMMONS@alphafalse
}
\DeclareOption{authoryear}{% enable author year citation style
    \COMMONS@numberedfalse%
    \COMMONS@authoryeartrue
    \COMMONS@alphafalse
}
\DeclareOption{alpha}{% enable alpha citation style
    \COMMONS@numberedfalse%
    \COMMONS@authoryearfalse
    \COMMONS@alphatrue
}
\newif\ifCOMMONS@list \COMMONS@listfalse
\DeclareOption{list}{% enable enhanced list structures
    \COMMONS@listtrue%
}
\newif\ifCOMMONS@color \COMMONS@colorfalse
\DeclareOption{color}{% enable color package to use color
    \COMMONS@colortrue%
}
\newif\ifCOMMONS@background \COMMONS@backgroundfalse
\DeclareOption{background}{% enable page background
    \COMMONS@colortrue% need a color package
    \COMMONS@backgroundtrue%
}
\newif\ifCOMMONS@tikz \COMMONS@tikzfalse
\DeclareOption{tikz}{% enable tikz package for complex diagrams
    \COMMONS@colortrue% need xcolor package
    \COMMONS@tikztrue%
}
\newif\ifCOMMONS@table \COMMONS@tablefalse
\DeclareOption{table}{% enable a table package for complex tables
    \COMMONS@tabletrue%
}
\newif\ifCOMMONS@math \COMMONS@mathfalse
\DeclareOption{math}{% enable math package
    \COMMONS@mathtrue%
}
%% end-user parameters, each option is declared by one declare option command
\DeclareOption*{% handle non-implemented options
    \PackageWarning{commons}{Unknown option '\CurrentOption'}%
}
%% terminates all options processing
\ProcessOptions\relax
%%%%% --------------------------------------------------------------------------------
%%
%%%%******************************* Required Packages ********************************
%%
%% Language Setting
\RequirePackage{ifpdf,ifxetex}
%% packages and settings depend on PDF mode
\ifxetex % running xelatex in PDF mode
%%%%% --------------------------------------------------------------------------------
%%
%%%%********************************** Xelatex ***************************************
%%
%%% >>> System Font Environment
%%
%% If compile by "xelatex", then it support system fonts.
%% Fonts and tweaks for xelatex:
\RequirePackage{fontspec}% fontspec package.
\defaultfontfeatures{Ligatures=TeX}% use tex style to support LaTeX quoting style.
%% -- Set English fonts.
%% Roman, or Serif - typefaces are named for the features at the ends of their strokes
%% determine \rmfamily, usually for main contents
%% because of \renewcommand*{\familydefault}{\rmdefault}, it's also determine \normalfont.
%% examples: Times New Roman, Garamond, Adobe Garamond Pro
%\setmainfont[BoldFont=Garamond-Bold,ItalicFont=Garamond-Italic]{Garamond}%
%% Sans serif - typefaces without strokes (without serif) to get high readability
%% determine \sffamily, usually for signage, headings that demanding high readability
%% examples: Helvetica, Gill Sans, Futura
%\setsansfont{Gill Sans MT}%
%% Monospaced - typefaces that every glyph is the same width (opposed to variable-width fonts).
%% determine \ttfamily, usually for programming, tabulated data, etc.
%% examples: Rockwell, Andale Mono, Courier, Monaco
%\setmonofont{Rockwell}%
\else
\ifpdf % running pdfTeX in PDF mode
%%%%% --------------------------------------------------------------------------------
%%
%%%%******************************** Pdflatex ****************************************
%%
%%% >>>  Input encoding and the font encoding
%%
%% Specify language.
%% Set Language you want to use: \RequirePackage[language]{babel}
%% You should place it soon after the \documentclass command, so that all the other
%% packages you load afterwards will know the language you are using.
%\RequirePackage[english]{babel}% language.
%% Specify input encoding.
\RequirePackage[utf8]{inputenc}% make sure your document is saved using the UTF-8 encoding.
%\RequirePackage[latin1]{inputenc}% latin encoding
%% Font encoding.
\RequirePackage[T1]{fontenc}% enable modern font encoding
%% Font package.
\RequirePackage{newtxtext,newtxmath}
%% Options:
%% Text + Math: Adobe Times Roman (Recommended)
%% - \RequirePackage{newtxtext,newtxmath}
%% Text + Math: Palatino
%% - \RequirePackage{palatino}
%% Text + Math: Adobe Times Roman
%% - \RequirePackage{mathptmx,newtxmath}
\fi
\fi
%%
%% >>> graphic packages
%%
\RequirePackage{graphicx}% graphics packages for including graphics
%\RequirePackage{caption}% caption options like:[margin=10pt,font=small,labelfont=bf]
\RequirePackage{subcaption}% subcaption package for subfigures
\RequirePackage[section]{placeins}% to prevent floats from being moved over section
%%
%% >>> Page Layout and Line Spacing
%%
\ifCOMMONS@myhdr% header and footer style
    \RequirePackage{fancyhdr}% fancy headers and footers
\fi
\ifCOMMONS@lscape% landscape layout
    \RequirePackage{fancyhdr}% fancy headers and footers
    %% Usage: \begin{landscape} [\thispagestyle{lscape}] text... \end{landscape}
    \RequirePackage{pdflscape}% landscape environment
    \RequirePackage[absolute]{textpos}% rotated page number
\fi
\ifCOMMONS@geometry% enable geometry to redefine page layout
    \RequirePackage{geometry}% page layout
    %\RequirePackage{setspace}% line spacing
\fi
\RequirePackage{microtype}% improves general appearance of the text
%%
%%% >>> Natural Sciences Citations and References
%%
%% if use bibtex citation, not need to use any packages!
%% if use natbib package, then:
\ifCOMMONS@numbered% enable numbered citation style
  % \RequirePackage[square,comma,numbers,sort&compress]{natbib}% square bracket
    %\RequirePackage[square,comma,super,sort&compress]{natbib}% superscripted square bracket
    %\bibliographystyle{elsarticle-num-names}% numbered scheme
   % \bibliographystyle{Biblio/gbt-7714-2015-numerical}% numbered scheme
\fi
\ifCOMMONS@authoryear% enable author year citation style
  %  \RequirePackage{natbib}% author year citation mode is the default
    %\bibliographystyle{elsarticle-harv}% author year scheme
 %   \bibliographystyle{Biblio/gbt-7714-2015-author-year}% numbered scheme
\fi
\ifCOMMONS@alpha% enable alpha citation style
  %  \RequirePackage[square,comma,numbers]{natbib}% square bracket
  %  \bibliographystyle{alpha}% alpha scheme
\fi
%%
%% >>> List Structures
%%
\ifCOMMONS@list% enable enhanced list and verbatim structures
    \RequirePackage{enumitem}% configure the enumerate environment
    \RequirePackage{listings}% useful for Algorithm and Coding
    %% Improves the verbatim environment, fixing some bugs. Moreover
    %% it provides the comment environment, that lets you add multiple-line
    %% comments or easily comment out big parts of the code.
    \RequirePackage{verbatim}
\fi
%%
%%% >>> Color
%%
\ifCOMMONS@color% enable color package to use color
    %\RequirePackage{color}%
    \RequirePackage[usenames,dvipsnames,table]{xcolor}%
\fi
%%
%%% >>> Tables
%%
\ifCOMMONS@table% enable a table for complex tables
    %% ctable package imports the array, tabularx and booktabs packages
    %% all commands from those packages are available as well.
    \RequirePackage{ctable}%
\fi
%%
%% >>> Math packages
%%
\ifCOMMONS@math% enable some extra math package
    \RequirePackage{mathtools,amstext,amsfonts,amssymb}
\fi
%%
%% >>> Tkiz
%%
%% Draw graphics directly with TeX commands
%% LaTeX/PGF/TikZ to draw procedural graphics directly with TeX commands.
%% Using TikZ in a LaTeX document requires loading the tikz package:
\ifCOMMONS@tikz% enable tikz for complex diagrams
    \RequirePackage{tikz}%
    %% This will automatically load the pgf package. To load further libraries use:
    \usetikzlibrary{
        positioning,
        arrows,
        calc,
        trees
    }%
\fi
%% Examples for libraries are "arrows", "automata", "backgrounds", "calendar",
%% "chains", "matrix", "mindmap", "patterns", "petri", "shadows", "shapes.geometric",
%% "shapes.misc", "spy", "trees".
%%
%% >>> hyperref packages
%%
%% packages and settings depend on PDF mode
\ifxetex % running xelatex in PDF mode
    \RequirePackage[xetex]{hyperref}
\else
    \ifpdf % running pdfTeX in PDF mode
        \RequirePackage[pdftex]{hyperref}
    \fi
\fi
%% Setting Hyperlinks
\hypersetup{% set hyperlinks.
    unicode=true,% allows non-Latin based languages in bookmarks
    %pdftitle={},% title
    %pdfauthor={},% author
    %pdfsubject={},% subject
    %pdfkeywords={keyword1}{key2} {key3},% list of keywords, and uncomment this line if desired
    %pdftoolbar=true,% show Acrobat's toolbar?
    %pdfmenubar=true,% show Acrobat's menu?
    pdffitwindow=false,% window fit to page when opened
    pdfstartview={FitH},% fits the width of the page to the window
    %pdfnewwindow=true,% links in new window
    %colorlinks=true,% false: boxed links; true: colored links
    %linkcolor=blue,% color of internal links
    %citecolor=green,% color of links to bibliography
    %filecolor=magenta,% color of file links
    %urlcolor=cyan,% color of external links
    bookmarksnumbered=true,% put section numbers in bookmarks
    hidelinks% remove link color and border.
}
%% it gives LaTeX the possibility to manage links
%% within the document or to any URL when you compile in PDF.
%% Just load the package in the preamble, at the end of all the
%% other packages but prior to other settings.
%%%%% --------------------------------------------------------------------------------
%%
%%%%**************************** Configuration Command *******************************
%%
%% >>> Extensions and Directories for graphics
%%
%% Declare graphic extensions for automatic selection when including graphics.
%% By avoiding supplying graphic extensions in \includegraphics command,
%% the source file can be more general and adaptive.
\ifxetex % running xelatex in PDF mode
    \DeclareGraphicsExtensions{.pdf,.eps,.ps,.tif,.jpg,.png,.bmp,.gif}%
\else
    \ifpdf % running pdfTeX in PDF mode
        \DeclareGraphicsExtensions{.pdf,.jpg,.jpeg,.png}%
        %% To support .eps, .tif for pdfTex, recommend using epstopdf converter
        %% on the command line only, rather than embedding into source files.
    \fi
\fi
\graphicspath{{Img/}}% search path for figures
%%
%%% >>> Page background:
%%
\ifCOMMONS@background% enable page background
    \definecolor{backgroundcolor}{rgb}{0.85,0.85,0.85}
    \pagecolor{backgroundcolor} % page background color, require a color package.
\fi
%%
%%% >>> Layout and Margin
%%
\ifCOMMONS@geometry% enable geometry to redefine page layout
    \geometry{paper=a4paper,left=25mm,right=24mm,top=45mm,bottom=5mm}% reduced margins at each side.
\fi
%%
%%% >>> Page header and footer Style
%%
%% Page styles in Latex terms refers not to page dimensions, but to the running headers
%% and footers of a document. These headers typically contain document titles, chapter
%% or section numbers/names, and page numbers.
%% configure fancy style
\ifCOMMONS@myhdr% user defined header and footer style
\pagestyle{fancy}
    \providecommand{\chaptermark}{}% compatibility for non book classes
    \providecommand{\thechapter}{}% compatibility for non book classes
    \providecommand{\CTEXthechapter}{\thechapter.}% compatibility for non ctex classes
    %% reset style of chapter and section mark to actual name
    \renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}}%
    \renewcommand{\sectionmark}[1]{\markright{\MakeUppercase{#1}}{}}%
    %% deactivate uppercase effect
    \renewcommand{\MakeUppercase}[1]{#1}
%% define different kinds of header and footer for different parts
\fancypagestyle{frontmatterstyle}{% style for frontmatter
    \fancyhf{}% clear fields
    \fancyhead[RE]{\small \@title}% structure elements
    \fancyhead[LO]{\small \leftmark}% structure elements
    \fancyhead[LE]{\small \thepage}% page number
    \fancyhead[RO]{\small \thepage}% page number
    \renewcommand{\headrulewidth}{1pt}% header rule
    \renewcommand{\footrulewidth}{0pt}% footer rule
}
\fancypagestyle{mainmatterstyle}{% style for mainmatter
    \fancyhf{}% clear fields
    \fancyhead[RE]{\small \@title}% structure elements
    \fancyhead[LO]{\small \CTEXthechapter\ \leftmark}% structure elements
    \fancyhead[LE]{\small \thepage}% page number
    \fancyhead[RO]{\small \thepage}% page number
    \renewcommand{\headrulewidth}{1pt}% header rule
    \renewcommand{\footrulewidth}{0pt}% footer rule
}
\fancypagestyle{backmatterstyle}{% header and footer style for backmatter
    \fancyhf{}% clear fields
    \fancyhead[RE]{\small \@title}% structure elements
    \fancyhead[LO]{\small \leftmark}% structure elements
    \fancyhead[LE]{\small \thepage}% page number
    \fancyhead[RO]{\small \thepage}% page number
    \renewcommand{\headrulewidth}{1pt}% header rule
    \renewcommand{\footrulewidth}{0pt}% footer rule
}
%% redefine \frontmatter to include the change
\providecommand{\frontmatter}{}% compatibility for non book classes
\let\myfrontmatter\frontmatter%
\renewcommand{\frontmatter}{%
    \myfrontmatter%
    \pagestyle{frontmatterstyle}%
}
%% redefine \mainmatter to include the change
\providecommand{\mainmatter}{}% compatibility for non book classes
\let\mymainmatter\mainmatter%
\renewcommand{\mainmatter}{%
    \mymainmatter%
    \pagestyle{mainmatterstyle}%
}
%% redefine \backmatter to include the change
\providecommand{\backmatter}{}% compatibility for non book classes
\let\mybackmatter\backmatter%
\renewcommand{\backmatter}{%
    \mybackmatter%
    \pagestyle{backmatterstyle}%
}
%% Some LaTeX commands, like \chapter, use the \thispagestyle command to automatically switch
%% to the plain page style, thus ignoring the page style currently in effect.
%% To customize even such pages you must redefine the plain pagestyle.
%% redefine plain style:
\fancypagestyle{plain}{%
    \fancyhf{}% clear fields
    \renewcommand{\headrulewidth}{0pt}% header rule
    \renewcommand{\footrulewidth}{0pt}% footer rule
}
\fi
\ifCOMMONS@lscape% configure landscape environment
\fancypagestyle{lscape}{% landscape layout style
    \fancyhf{}% clear fields
    \fancyfoot[CE,CO]{%
    %% textpos: \begin{textblock}{<blockwidth>}[0.5,0.5](<hpos>,<vpos>) text... \end{textblock}
    %% origin of the absolute coordinate is the top-left corner of the page
    %% [0.5,0.5] means reference point of the block is the middle
    \begin{textblock}{0.1}[0.5,0.5](0.85,0.5){\rotatebox{90}{\small \thepage}}\end{textblock}% position the page number
    }
    %% set units of <blockwidth>, <hpos>, and <vpos> arguments by corresponding modules 
    \setlength{\TPHorizModule}{8.5in}% set to the width of page
    \setlength{\TPVertModule}{11in}% set to the height of page
    \renewcommand{\headrulewidth}{0pt}% header rule
    \renewcommand{\footrulewidth}{0pt}% footer rule
}
\fi
%%%%% --------------------------------------------------------------------------------
\endinput
%% End of file
%%%%% --------------------------------------------------------------------------------
